//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using Mindscape.BackgroundMotion.Website.Controllers;
using Mindscape.BackgroundMotion.Website.Infrastructure;

namespace Mindscape.BackgroundMotion.Website.Views
{
  public sealed class SearchPresenter : PresenterBase<ISearchView, IContributionController>
  {
    /// <summary>
    /// This method is invoked by the view everytime it loads
    /// </summary>
    public override void OnViewLoaded()
    {
      int pageNumber = Controller.GetParameter<int>(Constants.Parameters.Page);

      ISearchResult results = Controller.Search(pageNumber);

      View.Results = results;
      View.DisplayNoDataMessage = (results.TotalResults == 0);

      View.RegisterRssFeed(string.Concat(
        "?", Constants.Parameters.Query, "=", Controller.GetParameter<string>(Constants.Parameters.Query), 
        "&", Constants.Parameters.Filter, "=", Controller.GetParameter<string>(Constants.Parameters.Filter)));
    }
  }
}